package com.the4man.cnbdw.action.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;

public class CommonAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    protected static final String ADD = "add";
    protected static final String CREATE = "create";
    protected static final String EDIT = "edit";
    protected static final String UPDATE = "update";
    protected static final String SHOW = "show";
    protected static final String DELETE = "delete";
    protected static final String INDEX = "index";
    public static final String JSON_PAGE = "jsonPage";
    protected static final String JSON_OBJECT = "jsonObject";
    private String respath;
    private String basepath;
    private String version;
    private String searchinfo;
    private Long nowDate;
    public String mytitle;
    public String mykeywords;
    public String mydescription;

    public CommonAction() {
    }

    public String getRespath() {
        return this.respath;
    }

    public String getBasepath() {
        HttpServletRequest request = ServletActionContext.getRequest();
        String path = request.getContextPath();
        String bp = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        this.basepath = bp;
        return this.basepath;
    }

    public Long getNowDate() {
        return (new Date()).getTime();
    }

    public void setBasepath(String basepath) {
        this.basepath = basepath;
    }

    public HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }

    public HttpServletResponse getResponse() {
        return ServletActionContext.getResponse();
    }

    public HttpSession getSession() {
        return this.getRequest().getSession();
    }

    public String getContextPath() {
        String path = this.getRequest().getContextPath();
        return this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort() + path + "/";
    }
}
